package com.loser.utils;


import java.util.Objects;

/**
 * 业务包裹类
 *
 * @author alan
 * @date 2022/5/30 19:09
 */
public class BeanWrapper<T> {

    private T bean;
    private Class<T> tClass;

    public static <T> BeanWrapper<T> init(Class<T> clazz) {
        return new BeanWrapper<>(clazz);
    }

    private BeanWrapper(Class<T> clazz) {
        this.tClass = clazz;
    }

    public T getBean() {

        if (Objects.nonNull(bean)) {
            return bean;
        }
        bean = ContextUtil.getBean(tClass);
        return bean;

    }

    public void setBean(T bean) {
        this.bean = bean;
    }

    public Class<T> gettClass() {
        return tClass;
    }

    public void settClass(Class<T> tClass) {
        this.tClass = tClass;
    }
}
